'''
Created on 14. jan. 2010

@author: per.pedersen
'''
import unittest
import CalculatorModule


class Test(unittest.TestCase):

    def setUp(self):
        self.calculator = CalculatorModule.Calculator()
    
    def test01CanInitializeCalculator(self):
        assert(self.calculator) 
    
    def test02WhenSumittingEmptyString_ShouldReturnZero(self):
            result = self.calculator.Add("")
            self.assertEqual(0, result)
    def test03WhenSubmittingSingleNumber_ShouldReturnNumber(self):
        result = self.calculator.Add("11")
        self.assertEqual(11, result)
    def test04WhenSubmittingMultipeNumbers_ShouldAddAll(self):
        result = self.calculator.Add("2, 4, 6, 7")
        self.assertEqual(19, result)            
    def test05WhenSubmittingWithNewlineSeparator_ShouldHandleInput(self):
        result = self.calculator.Add("2\n3\n4")
        self.assertEqual(9, result)
    def test06WhenMixingNewlineAndComma_ShouldHandleInput(self):
        result = self.calculator.Add("2\n3,4")
        self.assertEqual(9, result)
    def test07WhenSubmittingCustomDelimiter_ShouldHandleInput(self):
        result = self.calculator.Add("//;\n1;3;5")
        self.assertEqual(9, result)
    def test08WhenSubmittingNegativeNumber_ShouldThrowException(self):
        try:
            self.calculator.Add("2, 4, 6, -7")            
        except ValueError as e:
            self.assertEqual("Negative numbers not allowed", e.Description)
            return
        
        raise ValueError()
        
        
        
        
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()